package com.company.pdd;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[][] block = new long[N][2];
        for(int i = 0;i < N;i++){
            int pre = sc.nextInt();
            int nex = sc.nextInt();
            block[i][0] = pre;
            block[i][1] = nex;
        }
        long res = leastBlock(block);
        System.out.println(res);

        sc.close();
    }

    private static long leastBlock(long[][] block){

        Arrays.sort(block, new Comparator<long[]>() {
            @Override
            public int compare(long[] o1, long[] o2) {

                long s1 = o1[0] - o1[1];
                long s2 = o2[0] - o2[1];
                if(s1 == s2){
                    if(o1[0] > o2[0]){
                        return -1;
                    }else{
                        return 1;
                    }
                }else if(s1 > s2){
                    return -1;
                }else{
                    return 1;
                }
            }
        });


        long tempMax = 0;
        long add = 0;
        long temp = 0;

        for(int i = 0;i < block.length;i++){
            if(i == 0){
                tempMax = block[i][0];
                add = block[i][1];
            }else{
                temp = add + block[i][0];
                if(temp > tempMax){
                    tempMax = temp;
                }
                add += block[i][1];
            }
        }

        return tempMax;
    }
}
